package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.IPauseOrResetEngineeringOrderView;
import com.cloudsigns.factorymanager2.engineering.model.IPauseOrResetEngineeringOrderModel;
import com.cloudsigns.factorymanager2.engineering.model.PauseOrResetEngineeringOrderModel;

/**
 * Created by tony on 2018/4/5.
 */

public class PauseOrResetEngineeringOrderPresenter {
    private IPauseOrResetEngineeringOrderView view;
    private IPauseOrResetEngineeringOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public PauseOrResetEngineeringOrderPresenter(IPauseOrResetEngineeringOrderView view) {
        this.view = view;
        this.model = new PauseOrResetEngineeringOrderModel();
    }

    public void pauseOrResetEngineeringOrder() {


        model.pauseOrResetEngineeringOrder(view.getHasPauseOrder(), view.getOrderId(), view.getType(), new PauseOrResetEngineeringOrderModel.OnPauseOrResetEngineeringOrderListener() {
            @Override
            public void pauseOrResetEngineeringOrderSuccessed() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.pauseOrResetOrderSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void pauseOrResetEngineeringOrderFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.pauseOrResetOrderFailed(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
